using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Mechanism : BlockBase
{
    protected MaterialFloatAnimation materialAnimation;
    protected BoxCollider boxCollider;

    override protected void Awake()
    {
        materialAnimation = GetComponent<MaterialFloatAnimation>();
        boxCollider = GetComponent<BoxCollider>();
    }
    public virtual void TriggerOn()
    {
        materialAnimation.Play(0);
        boxCollider.enabled = true;
        LevelManager.instance.BuildNavMesh();
    }

    public virtual void TriggerOff()
    {
        materialAnimation.Play(1);
        boxCollider.enabled = false;
        BlockBase blockBase = LevelManager.instance.FindLastBlock(transform.position, this);
        if (blockBase != null)
        {
            blockBase.gameObject.SetActive(true);
        }
        LevelManager.instance.BuildNavMesh();

        if (CameraController.cameralook == CameraLook.Right)
        {
            gameObject.transform.position += Vector3.right * 1;
        }
        else if (CameraController.cameralook == CameraLook.Forward)
        {
            gameObject.transform.position += Vector3.back * 1;
        }
        else if (CameraController.cameralook == CameraLook.Top)
        {
            gameObject.transform.position += Vector3.up * 1;
        }
    }
}
